/*
 * Systemprogrammierung
 * Multiplayer-Quiz
 *
 * Server
 *
 * score.h: Implementierung des Score-Agents
 */

#include <semaphore.h>
#include <stdlib.h>
#include <pthread.h>
#include "score.h"
#include "common/sockets.h"
#include "common/util.h"

sem_t semPointsSemaphore;

sem_t *scoret_GetPointsSemaphore() {
	return &semPointsSemaphore;
}

void scoret_StartScoreThread() {
	pthread_t oThread;

	sem_init(&semPointsSemaphore, 0, 0);
	pthread_create(&oThread, NULL, scoret_ScoreThread, (void*)0);

	return;
}

void *scoret_ScoreThread(void *argument) {
	while (1) {
		// Wait for semaphore
		sem_wait(&semPointsSemaphore);
		// Broadcast Spieler/Punkte
		infoPrint("Now broadcasting...");
		sockets_ServerBroadcastPoints();
	}
	return NULL;
}
